/*
 * @Author: CJF
 * @Email: 1757818940@qq.com
 * @Date: 2022-02-24 20:42:43
 * @LastEditTime: 2022-02-25 20:24:53
 * @Description: 登录接口
 */
class LoginApi{
    constructor(){

    
    this.user=[]
    }
     
    getCode(){
        return new Promise(resolve=>{
            let codeNum = Math.floor(Math.random()*9000+1000)
            resolve( {code:200,
                data:{
                    codeNum
                }
              })
        })
       
        
    }
    login(phones){
        return new Promise(resolve=>{ 
            if(this.user.length==0){
                resolve({
                    code:404,
                    msg:'该账号未注册'
                })

            }
            else{
                let item = (this.user).find(it=>it.phone===phones )
         if(item){
             resolve({
                 code:200,
                 data:{
                     rows:item
                 },
                 token:'dD0FsadsFFasasd'+Date.now()+'sfeeCo9sbrmkkctFI'
             })
         }else{
            resolve({
                code:404,
                msg:'该账号未注册'
            })
         }
            }
         
        })
    }
    register(obj){
     return new Promise(resolve=>{
        let item = this.user.find(it=>it.phone===obj.phone)
        if(item){
            resolve({
                code:404,
                msg:'该账号已被注册'
            })
        }else{
            this.user.push({
                id:obj.phone,
                phone:obj.phone,
                name:obj.name,
            })
           resolve({
               code:200,
               msg:'注册成功'
           })
        }
     })
    }
    
    //   setUser(_data){
    //      this.user.push(_data)
       
    // }
    setUser(_data){
        return new Promise(resolve=>{
            this.user.push({..._data})
            resolve({
                code:200
            })
        })
    }
}

export default new LoginApi()
